package eleanor.ltd.isne.entities.roles.group;

import javax.persistence.AssociationOverride;
import javax.persistence.AssociationOverrides;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.Table;
import javax.persistence.Transient;

import eleanor.ltd.isne.entities.pages.action.PagesAction;
import eleanor.ltd.isne.entities.roles.Roles;

@Entity
@Table(name = "rolesgroup")
@AssociationOverrides({
	@AssociationOverride(name = "rgpk.roles", joinColumns = @JoinColumn(name = "roles_id")),
	@AssociationOverride(name = "rgpk.pagesAction.action", joinColumns = @JoinColumn(name = "pagesAction_action_id")),
	@AssociationOverride(name = "rgpk.pagesAction.pages", joinColumns = @JoinColumn(name = "pagesAction_pages_id")) })
public class RolesGroup {
	
	@EmbeddedId
	private RolesGroupPK rgpk = new RolesGroupPK();

	public RolesGroupPK getRgpk() {
		return rgpk;
	}

	public void setRgpk(RolesGroupPK rgpk) {
		this.rgpk = rgpk;
	}
	
	public void setRoles(Roles roles) {
		getRgpk().setRoles(roles);
	}
	
	@Transient
	public Roles getRoles() {
		return getRgpk().getRoles();
	}
	
	public void setPagesAction(PagesAction pagesAction) {
		getRgpk().setPagesAction(pagesAction);
	}
	
	@Transient
	public PagesAction getPagesAction() {
		return getRgpk().getPagesAction();
	}
	
	public boolean equals(Object o) {
		if (this == o)
			return true;
		if (o == null || getClass() != o.getClass())
			return false;

		RolesGroup that = (RolesGroup) o;

		if (getRgpk() != null ? !getRgpk().equals(that.getRgpk()) : that.getRgpk() != null)
			return false;

		return true;
	}
}
